package com.ashley.apptools.utils;

import com.ashley.apptools.provider.ToolsData.Category;
import com.ashley.apptools.vo.CategoryVo;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.database.Cursor;
import android.net.Uri;

public class CategoryContentResolver {
	public static final String[] SMALL_DATA = new String[]{Category._ID,Category.COLUMN_NAME_TITLE};
	public static final String DEFAULT_ID_SORT_ORDER = "_id DESC";
	public static final String DEFAULT_TITLE_SORT_ORDER = Category.COLUMN_NAME_TITLE+" DESC";
	
	public static Cursor getCategory(ContentResolver contentResolver,String[] projection,String sortOrder)
	{
		Cursor cursor = contentResolver.query(Category.CONTENT_URI, projection, null, null, sortOrder);
		return cursor;
	}
	public static Cursor getCategoryID(ContentResolver contentResolver,int uid,String[] projection)
	{
		Uri uri = ContentUris.withAppendedId(Category.CONTENT_ID_URI_PATTERN, uid);
		Cursor cursor =contentResolver.query(uri, projection, null, null, null);
		return cursor;
	}
	public static CategoryVo cursorToCategoryVo(Cursor cursor,int mode)
	{
		CategoryVo vo = new CategoryVo();
			int uid = cursor.getColumnIndex(Category._ID);
			int title = cursor.getColumnIndex(Category.COLUMN_NAME_TITLE);
			
			vo.setId(cursor.getInt(uid));
			vo.setTitle(cursor.getString(title));
			if(mode > 0)
			{
				int landing = cursor.getColumnIndex(Category.COLUME_LANDING);
				int warehouse = cursor.getColumnIndex(Category.COLUME_WAREHOVSE);
				int sale = cursor.getColumnIndex(Category.COLUME_SALE);
				
				vo.setLanding(cursor.getDouble(landing));
				vo.setWarehouse(cursor.getDouble(warehouse));
				vo.setSale(cursor.getDouble(sale));
			}
		
		return vo;
	}
	
}
